﻿using System.ComponentModel.Composition;
using Fisharoo.Common;
using Fisharoo.DataAccess.Interfaces;
using Fisharoo.Interfaces;
using Fisharoo.Web.Account.Interfaces;

namespace Fisharoo.Web.Account.Presenters
{
    public class RecoverPasswordPresenter
    {
        private IRecoverPassword _view;
        [Import]
        private IEmail _email;
        [Import]
        private IAccountRepository _accountRepository;

        public RecoverPasswordPresenter()
        {
            MEFManager.Compose(this);
        }

        public void Init(IRecoverPassword View)
        {
            _view = View;
        }

        public void RecoverPassword(string Email)
        {
            Fisharoo.DataAccess.Account account = _accountRepository.GetAccountByEmail(Email);

            if(account != null)
            {
                _email.SendPasswordReminderEmail(account.Email, account.Password, account.Username);
                _view.ShowRecoverPasswordPanel(false);
                _view.ShowMessage("An email was sent to your account!");
            }
            else
            {
                _view.ShowRecoverPasswordPanel(true);
                _view.ShowMessage("We couldn't find the account you requested.");
            }
            
        }
    }
}
